package com.itheima;

import java.util.HashSet;

public class Test1 {
    public static void main(String[] args) {
        
    }
    public int[] intersection(int[] nums1, int[] nums2) {
        HashSet<Integer> hs =new HashSet<>();
        HashSet<Integer> result =new HashSet<>();
        for(int i =0;i<nums1.length;i++){
            hs.add(nums1[i]);
        }
        for(int i =0;i<nums2.length;i++){
            if(hs.contains(nums2[i])){
                result.add(nums2[i]);
            }
        }
        int[] arr= new int[result.size()];
        int i =0;
        for(Integer h:result){
            arr[i++]=h;
        }
        return arr;
    }

}
